package com.woniuxy.yuekeuser.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.yuekeuser.controller.Form.CampsiteForm;
import com.woniuxy.yuekeuser.controller.Info.CampsiteInfo;
import com.woniuxy.yuekeuser.model.Campsite;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Freedom
 * @since 2020-11-03
 */
public interface CampsiteMapper extends BaseMapper<Campsite> {
    /**
     * 根据userid查询营地id
     */
    @Select("Select campsite_id from campsite where user_id = #{id}")
    public int findcampsiteIdByuserId(int id);


    /**
     * 根据商家id查询营地名字
     */
    @Select("Select campsite_name from campsite where user_id = #{id}")
    public String findcampsiteNameByuserId(int id);

//    //根据热度排名全部营地
//    @Select("SELECT\n" +
//            "campsite.campsite_area,\n" +
//            "campsite.campsite_name,\n" +
//            "campsite.campsite_address,\n" +
//            "campsite.campsite_facilities,\n" +
//            "campsite.campsite_activity,\n" +
//            "campsite.user_id,\n" +
//            "campsite.campsite_heat,\n" +
//            "campsite.campsite_id,\n" +
//            "campsite.campsite_rating\n" +
//            "FROM\n" +
//            "campsite\n" +
//            "ORDER BY\n" +
//            "campsite.campsite_heat DESC")
//    public List<Campsite> getAllCampsiteByHeat();

//    @Select("<script>" +
//            "SELECT\n" +
//            "campsite.campsite_area,\n" +
//            "campsite.campsite_name,\n" +
//            "campsite.campsite_address,\n" +
//            "campsite.campsite_facilities,\n" +
//            "campsite.campsite_activity,\n" +
//            "campsite.user_id,\n" +
//            "campsite.campsite_heat,\n" +
//            "campsite.campsite_id,\n" +
//            "campsite.campsite_rating\n" +
//            "FROM\n" +
//            "campsite\n" +
//            " <where>" +
//            "<if test='cityName!=null'>" +
//            " and campsite_area = #{cityName} " +
//            " </if>" +
//            "<if test='findCampsite!=null'>" +
//            " and campsite_name like CONCAT('%',#{findCampsite},'%')" +
//            " </if>" +
//            " </where>" +
//            "<if test='heat!=0'>" +
//            " order by campsite_heat desc " +
//            " </if>" +
//            "<if test='rating!=0'>" +
//            " order by campsite_rating desc " +
//            " </if>" +
//            " </script>" +
//            "")
//    public IPage<CampsiteForm> findAllCampsiteList(Page<CampsiteForm> page, String cityName,String findCampsite, int heat, int rating);
    //根据热度排名全部营地
    @Select("SELECT\n" +
            "campsite.campsite_id,\n" +
            "campsite.campsite_area,\n" +
            "campsite.campsite_name,\n" +
            "campsite.campsite_address,\n" +
            "campsite.campsite_facilities,\n" +
            "campsite.campsite_activity,\n" +
            "campsite.user_id,\n" +
            "campsite.campsite_heat,\n" +
            "campsite.campsite_rating,\n" +
            "`user`.user_id,\n" +
            "`user`.`status`\n" +
            "FROM\n" +
            "campsite\n" +
            "INNER JOIN `user` ON `user`.user_id = campsite.user_id\n" +
            "WHERE\n" +
            "`user`.`status` = \"正常\"\n" +
            "ORDER BY\n" +
            "campsite.campsite_heat DESC")
    public List<Campsite> getAllCampsiteByHeat();


    @Select("<script>" +
            "SELECT\n" +
            "campsite.campsite_id,\n" +
            "campsite.campsite_area,\n" +
            "campsite.campsite_name,\n" +
            "campsite.campsite_address,\n" +
            "campsite.campsite_facilities,\n" +
            "campsite.campsite_activity,\n" +
            "campsite.user_id,\n" +
            "campsite.campsite_heat,\n" +
            "campsite.campsite_rating,\n" +
            "`user`.user_id,\n" +
            "`user`.`status`\n" +
            "FROM\n" +
            "campsite\n" +
            "INNER JOIN `user` ON `user`.user_id = campsite.user_id\n" +
            " <where>" +
            "<if test='1==1'>" +
            "`user`.`status` = \"正常\"" +
            " </if>" +
            "<if test='cityName!=null'>" +
            " and campsite_area = #{cityName} " +
            " </if>" +
            "<if test='findCampsite!=null'>" +
            " and campsite_name like CONCAT('%',#{findCampsite},'%')" +
            " </if>" +
            " </where>" +
            "<if test='heat!=0'>" +
            " order by campsite_heat desc " +
            " </if>" +
            "<if test='rating!=0'>" +
            " order by campsite_rating desc " +
            " </if>" +
            " </script>" +
            "")
    public IPage<CampsiteForm> findAllCampsiteList(Page<CampsiteForm> page, String cityName,String findCampsite, int heat, int rating);

    @Select("SELECT\n" +
            "campsite.campsite_id,\n" +
            "campsite.campsite_area,\n" +
            "campsite.campsite_name,\n" +
            "campsite.campsite_address,\n" +
            "campsite.campsite_facilities,\n" +
            "campsite.campsite_activity,\n" +
            "campsite.user_id,\n" +
            "campsite.campsite_heat,\n" +
            "campsite.campsite_rating\n" +
            "FROM\n" +
            "campsite\n" +
            "WHERE\n" +
            "campsite.campsite_id = #{campsiteId}")
    public CampsiteInfo nowCampsiteById(int campsiteId);
}
